﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lfm.Parser
{
    /// <summary>
    /// DEPRECATED - SUPERSEEDED BY CUSTOM XLINQEXTENSIONS
    /// A set of safe converters that provide default values if they fail
    /// </summary>
    internal class Converters
    {
        public static Int32 ToInt32(String e)
        {
            if (e != null && e != String.Empty)
            {
                return Convert.ToInt32(e);
            }

            return 0;
        }

        public static long ToInt64(String e)
        {
            if (e != null && e != String.Empty)
            {
                return Convert.ToInt64(e);
            }

            return 0;
        }

        public static Double ToDouble(String e)
        {
            if (e != null && e != String.Empty)
            {
                return Convert.ToDouble(e);
            }

            return 0;
        }

        public static Boolean ToBool(String e)
        {
            if (e != null && e == "1") return true;
            else return false;
        }

        public static Uri ToUri(String e)
        {
            if (e != null && e != String.Empty)
            {
                return new Uri(e, UriKind.RelativeOrAbsolute);
            }
            else
            {
                return new Uri(String.Empty, UriKind.RelativeOrAbsolute);
            }
        }
    }
}
